package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

/**
  路由和路由组
*/
func main() {
	engine := gin.Default()
	//普通路由
	engine.GET("/demo", func(context *gin.Context) {
		context.JSON(http.StatusOK, gin.H{"msg": "demo"})
	})
	//匹配任意请求Method的路由
	engine.Any("/any", func(context *gin.Context) {
		context.JSON(http.StatusOK, gin.H{"msg": "any"})
	})
	//处理未匹配的路由
	engine.NoRoute(func(context *gin.Context) {
		context.JSON(http.StatusNotFound, gin.H{"msg": "NoRoute"})
	})
	//路由组
	userGroup := engine.Group("/user")
	{
		userGroup.GET("/list", func(context *gin.Context) {
			context.JSON(http.StatusNotFound, gin.H{"msg": "user.list"})
		})
		userGroup.POST("/add", func(context *gin.Context) {
			context.JSON(http.StatusNotFound, gin.H{"msg": "user.add"})
		})
	}
	stuGroup := engine.Group("/student")
	{
		stuGroup.GET("/list", func(context *gin.Context) {
			context.JSON(http.StatusNotFound, gin.H{"msg": "student.list"})
		})
		stuGroup.POST("/add", func(context *gin.Context) {
			context.JSON(http.StatusNotFound, gin.H{"msg": "student.add"})
		})
	}
	engine.Run(":8088")
}
